### FILE="Main.annotation"
# Copyright:	Public domain.
# Filename:	FRESH_START_AND_RESTART.agc
# Purpose:	Part of the source code for Solarium build 55. This
#		is for the Command Module's (CM) Apollo Guidance
#		Computer (AGC), for Apollo 4.
# Assembler:	yaYUL --block1
# Contact:	Jim Lawton <jim DOT lawton AT gmail DOT com>
# Website:	www.ibiblio.org/apollo/index.html
# Page scans:	www.ibiblio.org/apollo/ScansForConversion/Solarium055/
# Mod history:	2009-09-28 JL	Created.

## Page 140

		BANK	4
#	FRESH START - A KEYBOARD REQUEST TO INITIALIZE THE SYSTEM.

SLAP1		INHINT			# COMES HERE FROM THE PINBALL VERB FAN.
		CAF	ZERO		#  (ZERO FAILREG IN FRESH START ONLY).
		TS	FAILREG
		TS	MODREG
		TS	REDOCNTR	# ZERO ONLY DURING FRESH START.

		CAF	BIT4		# DISABLE IMU FAIL FOR 5 SECS.
SLAP2		TS	OLDERR		#  CURTAINS ENTERS HERE FROM THATSALL.
					# DSPLOCK (BIT 4 OF STATE), UPLOCK (BIT2 OF
					# STATE), EXTVBACT (BIT3 OF STATE) ARE
					# ZEROED BELOW (FRESH START ONLY).
		CAF	ZERO
		TS	ERCOUNT
		
		TC	STARTSUB	# SUBROUTINE DOES MOST OF THE WORK.

NOGO		CAF	MAXPROG		# MAKE ALL RESTART GROUPS INACTIVE.
		TS	BUF
		CS	ONE
		INDEX	BUF
		TS	PHASE1
		COM
		INDEX	BUF
		TS	-PHASE1
		
		CCS	BUF
		TC	NOGO +1
		
		TS	OUT1		# RESET OUT1 HERE INSTEAD OF IN STARTSUB.
		TS	SMODE		# DISABLE SELF-CHECK.
		
		CAF	BIT15		# TELL T4RUPT TO TURN OFF ALL C RELAYS.
DSP12D		TS	DSPTAB +12D
DSP13D		TS	DSPTAB +13D

		CAF	OCT40010
DSP11D		TS	DSPTAB +11D	# LEAVE IMU IN FINE ALIGN

		TS	WASKSET		# DISABLE KSAMP DURING INITIAL TRANSIENT.
		
		CAF	BIT5		# FOR 160 MS.
		TC	WAITLIST
		CADR	KENABLE
		
		XCH	IN3
		XCH	IN3
		MASK	OPTMODES
## Page 141
		TS	WASOPSET
		
		CAF	SWINIT
		TS	STATE
		CAF	SWINIT +1
		TS	STATE +1
		CAF	SWINIT +2
		TS	STATE +2
		
		CS	OLDERR
		MASK	BIT5
		CCS	A
		TC	STARTSW
		
		TC	ALARM
		OCT	00301
		
STARTSW		TC	ENDFRESH
ESTART		CAF	PRIO25
		TC	FINDVAC
		CADR	BEGIN501
		
		TC	ENDFRESH
		
KENABLE		CAF	OCT50
		TS	WASKSET
		CAF	BIT10
		TC	WAITLIST
		CADR	IFAILOK
		
		TC	TASKOVER
		
THATSALL	TS	SFAIL
		INHINT
		CAF	BITS4&5
		TC	SLAP2
		
MAXPROG		EQUALS	FIVE
BITS4&5		OCT	30

BITS5&7		OCT	120

## Page 142

# 	WHENEVER A GO SEQUENCE (GOJAM) IS FIRED,  GOPROG  IS CALLED TO RESTART ANY COMPUTER ACTIVITY THAT
# MAY HAVE BEEN GOING ON AT THE TIME. (A NUMBER OF ALARMS SUCH AS PARITY FAILURE OR POWER FAILURE CAUSE GOJAM).
# THE FUNCTION OF GOPROG IS TO INITIALIZE THE COMPUTER SUB-SYSTEM (I.E., NO C RELAYS ARE CHANGED, ETC.) AND
# RESTART ALL MAJOR ROUTINES WHOSE PHASE BITS INDICATE ACTIVITY.

GOPROG		CCS	ERESTORE	# RESTORE TWO ERASABLE REGISTERS IF
		TC	+2		# RESTART OCCURS WHILE SELF-CHECK HAS
		TC	GOPROG2		# REMOVED CONTENTS OF THESE REGISTERS.
		CS	1776
		CS	A
		NDX	1777
		TS	0001		# RESTORE C(X)
		CS	1775
		CS	A
		NDX	1777
		TS	0000		# RESTORE C(X-1)
GOPROG2		CAF	DVMONMSK	# SHOULD BE SYS FLAG FOR ENGINE ON.
		MASK	FLAGWRD1
		CCS	A		# SEE IF ENGINE WAS ON.
		CAF	BIT13		# YES..PUT IT BACK ON.
		TS	OUT1		# NO...ZERO IT.
		
		CAF	TWO		# SET RESTART FAIL INDICATION, WHICH WILL
		TS	OLDERR		# BE REMOVED AFTER SUCCESSFUL VERIFICATION
		TC	STARTSUB	# OF PHASE TABLE AGREEMENT.
		
		XCH	IN0		# IF BOTH ERROR RESET AND MARK ARE
		MASK	HUNGMASK	# DEPRESSED, FALL INTO FRESH START TO
		AD	HUNGCODE	# HOPEFULLY PREVENT OR STOP RECURRING GOS.
		CCS	A
		TC	PHASECHK -1	# RESTART
HUNGCODE	OCT	37775		# COMPLEMENT OF IN0 HUNG SETTING.
		TC	PHASECHK -1	# RESTART
		TC	NOGO
		
		CAF	MAXPROG		# PHASE BITS ARE KEPT IN TWO COPIES,
PHASECHK	TS	MPAC		# ONE DIRECT AND ONE COMPLEMENTED. THIS
		INDEX	A		# SECTION MAKES SURE ALL ENTRIES IN EACH
		CS	PHASETAB	# SATISFIES THIS RULE AS AN INDICATION OF
		TS	BUF		# THE GOODNESS OF ERASABLE MEMORY. IF THE
		COM			# TEST FAILS, DO A FRESH START WITH THE
		INDEX	MPAC		# MODE LIGHTS SET TO 00 TO TELL THE STORY.
		MASK	PHASEBAR
		TC	ZEROTEST	# P.(-P) AND (-P).(--P) SHOULD BOTH BE
		INDEX	MPAC		# +0 FOR A LOGICAL MATCH.
		CS	PHASEBAR
		MASK	BUF
		TC	ZEROTEST
		
		CCS	MPAC
## Page 143
		TC	PHASECHK
		
		TS	DISPCNTR	# ENABLE VG DISPLAY GRAB
		TS	OLDERR		# NO RESTART FAIL.
		CAF	ONE		# INCREMENT REDOCNTR.
		AD	REDOCNTR
		TS	REDOCNTR
		
		CS	BIT15
		MASK	DSPTAB +13D	# PICK UP ALL BUT BIT 15.
		AD	BIT15		# SET BIT 15 TO FORCE RESETTING RELAYS.
		TS	DSPTAB +13D	# MIGHT TAKE A WHILE TO GET OUT.
		
CHECKIN3	XCH	IN3		# PUT PRESENT MODES INTO WAS  REGISTERS.
		XCH	IN3
		TS	WASKSET
		MASK	LOW7
		XCH	WASKSET
		MASK	OPTMODES
		TS	WASOPSET
		
		CAF	BITS5&7		# IMU ATTITUDE CONTROL OR ENTRY MODE.
		MASK	WASKSET
		CCS	A		# IS IT IN ONE OF THESE MODES.
		CS	ZERO		# YES.. PUT +0 INTO CDUIND.
		COM			# NO... PUT -0 INTO CDUIND.
		TS	CDUIND
		
		CCS	IN0
		TC	GOJUMP
		TC	GOJUMP
		TC	+1
		CS	BIT12
		MASK	WASOPSET
		TS	WASOPSET

## Page 144

GOJUMP		CAF	MAXPROG		# SCAN PHASE TABLE FOR ACTIVITY.
		TS	LOC
		
		RELINT			# OPEN THE INTERRUPT GATE SO THAT EACH
		INHINT			# GO DISPATCH HAS 10 MS.
		
		AD	ONE		# GROUP NUMBER IN PROG.
		TS	PROG
		INDEX	A		# SEE IF GROUP ACTIVE.
		CCS	PHASE1 -1
		TC	PROGON		# VALID IF PHASE LESS THAN 127.
		TC	GOTERM		# DO REQUESTED PHASE TERMINATE.
		CCS	A		# INACTIVE IF PHASE = -1.
		TC	RSTFAIL2	# BAD DATA IF -0.
GORETURN	CCS	LOC
		TC	GOJUMP +1
		
		CAF	PRIO37		# FIRE UP JOB TO DISPLAY FAILREG
		TC	NOVAC
		CADR	DOALARM
		
ENDFRESH	RELINT
		TC	BANKCALL	# DISPLAY MAJOR MODES.
		CADR	DSPMM
		
		TC	POSTJUMP
		CADR	DUMMYJOB	# THIS REVERTS TO THE IDLING JOB.
		
ZEROTEST	CCS	A
		TC	NOGO		# RESTART FROM GO IMPOSSIBLE.
		TC	Q		# OK SO FAR
		TC	NOGO
		TC	NOGO

## Page 145

#   INTERNAL RESTART BY PROGRAM CONTROL TO FLUSH OUT WAITLIST AND EXEC.

ENEMA		INHINT			# A STRANGE INSTRUCTION TO BEAR THIS NAME.
		TC	STARTSUB
		
		CS	ZERO
		TS	SFAIL
		
		TC	CHECKIN3

## Page 146

#	DISPATCH OR TERMINATE RESTART GROUPS.

PROGON		AD	ONE		# PHASE BITS TO MPAC.
		TS	MPAC
		CS	LOW7		# CHECK SIZE.
		MASK	MPAC
		CCS	A
		TC	RSTFAIL2	# RESTART FAIL - OUT OF RANGE.
		
		INDEX	LOC		# JUMP TO GOCADR LOC.
		CAF	GOCADR
		TC	SWCALL
		
		TC	GORETURN	# ON RETURN FROM SWCALL.
		
GOTERM		CS	ONE		# IF A RESTART GROUP HAD BEEN REQUESTED TO
		INDEX	LOC		# TERMINATE, DO THE TERMINATE NOW.
		TS	PHASE1
		COM
		INDEX	LOC
		TS	-PHASE1
		TC	GORETURN
		
RSTFAIL2	CAF	TWO		# BAD DATA IN RESTART TABLES - FAIL.
		TS	OLDERR
		TC	NOGO

## Page 147

#	INITIALIZATION SUBROUTINE, CONTAINING INITIALIZATION COMMON TO BOTH FRESH START (KEYBOARD REQUEST) AND
# RESTART (IN RESPONSE TO A GO SEQUENCE).

STARTSUB	XCH	Q
		TS	BUF		# EXEC TEMPS ARE AVAILABLE TO US.
		
		CAF	POSMAX		# T3 AND T4 OVERFLOW AS SOON AS POSSIBLE.
		TS	TIME3		#   (POSMAX IS PSEUDO INTERRUPT SIGNAL IN
		TS	TIME4		#   CASE RUPT SIGNALLED BEFORE TS TIME3),
		
		CAF	NEG1/2		# INITIALIZE WAITLIST DELTA-TS.
		TS	LST1 +6
		TS	LST1 +5
		TS	LST1 +4
		TS	LST1 +3
		TS	LST1 +2
		TS	LST1 +1
		TS	LST1

		CS	ENDTASK		# SET ALL TASKS TO DUMMY TASK.
		TS	LST2 +7
		TS	LST2 +6
		TS	LST2 +5
		TS	LST2 +4
		TS	LST2 +3
		TS	LST2 +2
		TS	LST2 +1
		TS	LST2

		CS	ZERO		# MAKE ALL EXECUTIVE REGISTER SETS
		TS	PRIORITY +8D	# AVAILABLE (EXCEPT THIS ONE).
		TS	PRIORITY +16D
		TS	PRIORITY +24D
		TS	PRIORITY +32D
		TS	PRIORITY +40D
		TS	PRIORITY +48D
		TS	PRIORITY +56D

		TS	DSRUPTSW	# -0 GIVES US 40 MS TO GET READY FOR T4.
		TS	CDUIND		# MAKE IMU AND OPTICS AVAILABLE.
		TS	OPTIND

## Page 148

		CAF	VAC1ADRC	# MAKE ALL VAC AREAS AVAILABLE.
		TS	VAC1USE
		AD	LTHVACA
		TS	VAC2USE
		AD	LTHVACA
		TS	VAC3USE
		AD	LTHVACA
		TS	VAC4USE
		AD	LTHVACA
		TS	VAC5USE

		CAF	BIT10		# THIS REGISTER SET BECOMES DUMMY JOB.
		TS	PRIORITY
		
		CAF	TEN		# TURN OFF ALL DISPLAY SYSTEM RELAYS
DSPOFF		TS	MPAC
		CS	BIT12
		INDEX	MPAC
		TS	DSPTAB
		CCS	MPAC
		TC	DSPOFF

		TS	ERESTORE
		TS	UPLINK		# THESE MIGHT PICK UP AN INCREMENT DURING
		TS	56		# A GO.
		TS	DSPCNT		# SKIPS TO HERE WHEN FINISHED WITH C(A)=0.
		TS	NEWJOB
		TS	CADRSTOR
		TS	REQRET
		TS	CLPASS
		TS	MONSAVE		# KILL MONITOR
		TS	MONSAVE1
		TS	GRABLOCK
		TS	VERBREG
		TS	NOUNREG
		TS	DSPLIST
		TS	DSPLIST +1
		TS	DSPLIST +2
## Page 149
		TS	LGYRO		# MAKE GYRO ROUTINES AVAILABLE.
		TS	GCOMP		# ZERO COMPENSATING GYRO TORQUES.
		TS	GCOMP +1
		TS	GCOMP +2
		TS	GCOMP +3
		TS	GCOMP +4
		TS	GCOMP +5
		TS	DESKSET		# NO COMPUTER COMMAND.
		TS	DESOPSET	# (SAME AS IMU).
		TS	IMUCADR		# INITIALIZE MODE-SWITCHING.
		TS	OPTCADR
		TS	TMMARKER
		TS	MARKSTAT	# MAKE MARK SYSTEM AVAILABLE.
		
		CS	TIME1		# SAVE TIME OF LAST RESTART. (MINUS VALUE)
		TS	REDOTIME +1
		
		CAF	SIX		# (MAY NOT GET ANY ENDPULSES BEFORE T4).
		TS	TELCOUNT
		
		CAF	LPHASE1
		TS	DNTMGOTO
		
		CAF	LDNLST1
		TS	DNLSTADR
		
		CAF	NOUTCON
		TS	NOUT
		
		CS	BIT3/4		# ZERO ONLY DSPLOCK (BIT4 OF STATE) AND
		MASK	STATE		# EXTVBACT (BIT3 OF STATE) FOR RESTART.
		TS	STATE		# UPLOCK (BIT2 OF STATE) IS ZEROED ONLY
					# IN FRESH START.
		CS	VD1
		TS	DSPCOUNT
		TC	BUF		# DONE.

## Page 150

HUNGMASK	OCT	40037		# KEYCODE AND MARK BUTTON ONLY
OPTMODES	OCT	35000

OCT50		OCT	50		# FINE ALIGN + TRANSFER SWITCH.
OCT40010	OCT	40010		# IMU FINE ALIGN C-RELAY SETTING.
LPHASE1		ADRES	DNPHASE1
BIT3/4		OCT	14
NOUTCON		DEC	11



GOCADR		CADR	ENDOFJOB	# FOR 501 ONLY
		CADR	RESTARTS	# GROUP 2 RESTARTS.
		CADR	RESTARTS	# GROUP 3 RESTARTS.
		CADR	RESTARTS	# GROUP 4 RESTARTS.
		CADR	RESTARTS	# GROUP 5 RESTARTS.
		CADR	RESTARTS	# GROUP 6 RESTARTS.

VAC1ADRC	ADRES	VAC1USE
LTHVACA		DEC	44

SWINIT		OCT	01340
		OCT	00000		# STATE +1
		OCT	00000		# STATE +2
